import smtplib

from email.header import Header
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.utils import formataddr

sender = "cjl_spy@163.com"

message = MIMEMultipart()
message['From'] = formataddr(["cjl", sender])  # 发送者
message['To'] = formataddr(["你好", sender])  # 接收者

subject = 'Python 附件发送'
message['Subject'] = Header(subject, 'utf-8')

att2 = MIMEText(open('send_file.py', 'rb').read(), 'base64', 'utf-8')
att2["Content-Type"] = 'application/octet-stream'
att2["Content-Disposition"] = 'attachment; filename="send_file.py"'
message.attach(att2)

ser = smtplib.SMTP()

ser.connect("smtp.163.com", 25)
ser.login("cjl_spy@163.com", "power12345")

ser.sendmail("cjl_spy@163.com", ["cjl_spy@163.com"], message.as_string())
